package com.yzfarm.biujoke.biujoke.mvp.view;

import android.app.Activity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;

import com.yzfarm.biujoke.biujoke.R;
import com.yzfarm.biujoke.biujoke.mvp.base.SimpleFragment;
import com.yzfarm.biujoke.biujoke.mvp.model.datamanager.RetrofitManager;
import com.yzfarm.biujoke.biujoke.mvp.model.http.MeiNvApis;
import com.yzfarm.biujoke.biujoke.ui.adapter.Star12RecyclerAdpter;
import com.yzfarm.biujoke.biujoke.utils.pojo.NewMeinvItem;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hanhy on 2016/10/9.
 */

public class PicFragment extends SimpleFragment {

    private RecyclerView recyclerView;
    private Star12RecyclerAdpter adpter;
    private GridLayoutManager gridLayoutManager;
    private List<NewMeinvItem> list;
    public PicFragment(){

    }
    @Override
    protected int getLayoutId() {
        return R.layout.pic_layout;
    }

    @Override
    protected void initEventAndData() {
        list = new ArrayList<NewMeinvItem>();
        recyclerView = (RecyclerView) getView().findViewById(R.id.star12_content);
        gridLayoutManager = new GridLayoutManager(getContext(),2);
        recyclerView.setLayoutManager(gridLayoutManager);
        adpter = new Star12RecyclerAdpter(getContext(),list);
        recyclerView.setAdapter(adpter);

        RetrofitManager.getInstance().getMeiNvApis().getNewMeiNvs(new MeiNvApis.MeinvApiCallback<List<NewMeinvItem>>(){
            @Override
            public void onSuccess(final List<NewMeinvItem> list) {
                ((Activity)getContext()).runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        PicFragment.this.list = list;
                        Log.d("Test","onSuccess list " + list.size());
                        adpter.setmData(list);
                        adpter.notifyDataSetChanged();
                    }
                });

            }
        });
    }
}
